package com.rede.didiok.sms.event;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.rede.didiok.common.exception.exceptionType.FeignException;
import com.rede.didiok.common.feign.AdminFeignClient;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.feign.RankFeignClient;
import com.rede.didiok.common.feign.UserFeignClient;
import com.rede.didiok.common.utils.R;
import com.rede.didiok.common.utils.RedisUtil;

/**
 * AT事件处理器
 */

@Slf4j
@Component
public class AtEventHandler {


    @Resource
    private UserFeignClient userFeignClient;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private AdminFeignClient adminFeignClient;
    @Resource
    private RankFeignClient rankFeignClient;
    @Resource
    private CommunityFeignClient communityFeignClient;


    /**
     * at事件通用处理方法
     *
     * @param message
     */
    public void atEventHandler(String userUid, String toUserUid, String bizUid, String bizType, String message) {
        this.atEventHandler(userUid, toUserUid, null, bizUid, bizType, message, true);
    }

    /**
     * at事件通用处理方法
     *
     * @param message
     */
    public void atEventHandler(String userUid, String toUserUid, String toUid, String bizUid, String bizType, String message, boolean isAt) {
        // 判断消息中，是否有AT请求
        log.info("消息处理: {}", message);
        R result = userFeignClient.atEventHandler(userUid, toUserUid, toUid, bizUid, bizType, message, isAt);

        if(result.getCode()!=0){
            throw new FeignException("feign调用异常(at事件通用处理方法失败)");
        }
    }
}
